package org.ws.task.example.batch;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.ws.task.builder.TaskBuilder;
import org.ws.task.item.ItemLeaderCommit;
import org.ws.task.item.ItemLeaderProvider;
import org.ws.task.item.PullTask;
import org.ws.task.model.TaskItem;
import org.ws.task.model.TaskConfig.SendModel;

import java.io.FileNotFoundException;

@Configuration
public class TaskConfig {

    @Value("${uuid-file-path}")
    private String uuidFilePath;

    @Bean
    public PullTask<String> uuidPullTask() throws FileNotFoundException {
        return TaskBuilder.builder("uuidPullTask")
                .config()
                .chunk(10)
                .fetchTimeout(10_000)
                .sendModel(SendModel.CLUSTERING)
                .leaderProcess(false)
                .<String>pull()
                .provider(uuidItemProvider())
                .builder();
    }

    @Bean
    public ItemLeaderProvider<String> uuidItemProvider() throws FileNotFoundException {
        return new FileLineItemLeaderProvider(uuidFilePath);
    }
}
